<!-- 解除车位绑定-->
<template>
	<view>
		<view>
			<view class="cu-steps" v-if="roomDetail.status == '进行中'">
				<view class="cu-item" :class="index>1?'':'text-green'" v-for="(item,index) in steps" :key="index">
					<text :class="'cuIcon-' + item.cuIcon"></text> {{item.name}}
				</view>
			</view>

			<view class="block__title">车位信息</view>
			<view class="cu-form-group">
				<view class="title">提交人姓名</view>
				{{roomDetail.submitter}}
			</view>
			<!-- 			
			<view class="cu-form-group">
				<view class="title">位置</view>
				{{roomDetail.floorNum}}号楼{{roomDetail.unitNum}}单元{{roomDetail.roomNum}}室
			</view> -->
			<view class="cu-form-group">
				<view class="title">车位名称</view>
				{{roomDetail.examineObjectName}}
			</view>
			<view class="cu-form-group" v-if="carDetails.area">
				<view class="title">车位面积</view>
				{{carDetails.area}} 平方米
			</view>
			<!-- 			<view class="cu-form-group">
				<view class="title">车牌号</view>
				<view class="change_content">
					<input :type="isButton?'button':'text'" @keyup.enter="isText"
						v-model="plateNumber">
				</view>
			</view> -->
			<view class="cu-form-group" v-if="carDetails.state == 1">
				<view class="title">车位状态</view>
				在场
			</view>
			<view class="cu-form-group" v-if="carDetails.state == 2">
				<view class="title">车位状态</view>
				空闲
			</view>
			<view class="cu-form-group" v-if="carDetails.typeCd == 1">
				<view class="title">停车场类型</view>
				地上
			</view>
			<view class="cu-form-group" v-if="carDetails.typeCd == 2">
				<view class="title">停车场类型</view>
				地下
			</view>
			<view class="cu-form-group" v-if="carDetails.parkingType == 1">
				<view class="title">车位类型</view>
				已售
			</view>
			<view class="cu-form-group" v-if="carDetails.parkingType == 2">
				<view class="title">车位类型</view>
				未售
			</view>
			<view class="cu-form-group" v-if="carDetails.parkingType == 3">
				<view class="title">车位类型</view>
				出租
			</view>
			<view class="cu-form-group" v-if="roomDetail.houseName">
				<view class="title">房屋名称</view>
				{{roomDetail.houseName}}
			</view>
			<view class="cu-form-group" v-if="roomDetail.carPlate">
				<view class="title">车牌号</view>
				{{roomDetail.carPlate}}
			</view>
			<view class="cu-form-group" v-if="carDetails.createTime">
				<view class="title">提交绑定时间</view>
				{{carDetails.createTime}}
			</view>

			<view>
				<!-- 普通弹窗 -->
				<uni-popup ref="popup" background-color="#fff" isButton>
					<view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }">
						<view class="" style="width: 600rpx;padding:20rpx;background-color: white;">
							<view>


								<view class="cu-form-group arrow" @tap="chooseHouse()">
									<view class="title">房屋</view>
									<input required readonly label="房屋编号" v-model="houseName" class="text-right"
										placeholder="请选择房屋" name="houseName" icon="arrow"></input>
									<text class='cuIcon-right'></text>
								</view>


								<view class="cu-form-group">
									<view class="title">车牌号</view>
									<input v-model="plate" style="text-align:right" placeholder="请输入"></input>
								</view>
							</view>
							<view class="btn" style="display: flex;justify-content: space-around;margin-top: 70rpx;">
								<button style="width: 160rpx;height: 70rpx;line-height: 70rpx;" type="warn"
									@click="cancelCar">取消</button>
								<button style="width: 160rpx;height: 70rpx;line-height: 70rpx;" type="primary"
									@click="ensure">确认</button>
							</view>
						</view>
					</view>
				</uni-popup>
			</view>

			<view class="bottomRegion">
				<view class="vacantHouse" v-if="roomDetail.status == '通过'">
					<view v-if="!roomDetail.carPlate">
						<button @click="changeContent(roomDetail)" type="primary">关联车牌号</button>
					</view>
					<view v-else>
						<button @click="changeContent(roomDetail)" type="primary">修改车牌号</button>
					</view>
					<button @click="houseUnbundling" type="warn">解除车位绑定</button>
				</view>
				<view class="vacantHouse" v-else>
				</view>
			</view>


			<view class="cu-modal" :class="delOwnerMemberFlag==true?'show':''">
				<view class="cu-dialog">
					<view class="cu-bar bg-white justify-end">
						<view class="content">温馨提示</view>
						<view class="action" @tap="_cancleCall()">
							<text class="cuIcon-close text-red"></text>
						</view>
					</view>
					<view class="padding-xl">
						您确认解除该成员车位申请？
					</view>
					<view class="cu-bar bg-white justify-end">
						<view class="action margin-0 flex-sub  solid-left" @tap="_cancleDeleteOwnerMember()">取消</view>
						<view class="action margin-0 flex-sub text-green solid-left" @tap="_doDeleteOwnerMember()">确认
						</view>
					</view>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	// pages/my/myHouseDetail.js
	import context from '../../lib/java110/Java110Context.js';
	const constant = context.constant;
	const factory = context.factory;
	import {
		deleteCarBind
	} from '../../api/owner/ownerApi.js'

	export default {
		data() {
			return {
				type: '',
				isButton: true,
				houseCarTypes: '',
				houseTypeIndex: '',
				plate: '',
				houseName: '',
				houseId: '',
				bindCarNumberState: '',


				examineObjectId: '',
				carDetails: '',
				plateNumber: '',
				psId: '',
				stepsData: '',
				steps: [{
					cuIcon: 'usefullfill',
					name: '待绑定',
					desc: ''
				}, {
					cuIcon: 'radioboxfill',
					name: '申请中',
					desc: ''
				}, {
					cuIcon: 'roundcheckfill',
					name: '已绑定',
					desc: ''
				}],
				delOwnerMemberFlag: false, //解除房屋绑定弹窗
				ownerInfo: {},
				// 用户信息
				userInfo: {},
				// 用户信息
				ownerFlag: false,
				// 是否有业主信息 标记 如果有为 true  没有为false
				roomDetail: {},
				curOwnerMember: {},
				listId: {},
				plotCommunityId: '',
				identityType: "",
				examineObjectName: '',
				succTittle: "",
			};
		},

		components: {},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			let _that = this;
			_that.plotCommunityId = uni.getStorageSync("_selectCommunity");
			_that.plotCommunityId = _that.plotCommunityId.id
			_that.roomDetail = JSON.parse(options.room);
			console.log("_that.roomDetail", _that.roomDetail)
			_that.examineObjectId = _that.roomDetail.examineObjectId //需要删除车位的id
			_that.listId = _that.roomDetail.id //点击进入列表的id
			_that.examineObjectName = _that.roomDetail.examineObjectName
			_that.carPlate = _that.roomDetail.carPlate
			let identity = uni.getStorageSync("bindUserInfo");
			_that.identityType = identity.proprietorRole

			_that.loadXqInfo();
			_that.chooseCar()
		},

		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			let _homeNum = uni.getStorageSync("haBindHouse");
			if (_homeNum != null && _homeNum != undefined && _homeNum != '') {
				this.houseName = _homeNum.houseName;
				this.houseId = _homeNum.id; //楼栋id
			}
		},

		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},

		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},

		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},

		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {},

		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {},
		methods: {

			change(e) {
				this.show = e.show
			},
			changeContent(roomDetail) {
				this.type = 'center'
				// open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
				this.$refs.popup.open("center")
			},
			cancelCar() {
				this.$refs.popup.close()
			},
			ensure() {
				uni.request({
					url: constant.url.bindCarNumber,
					header: context.getHeaders(),
					method: "POST",
					data: {
						"carPlate": this.plate,
						"houseId": this.houseId,
						"houseName": this.houseName,
						"id": this.listId,
						"placeId": this.examineObjectId,
					},
					success: (res) => {
						uni.navigateBack({
							url: "pagesA/parkingInfo/myParking"
						})
						this.bindCarNumberState = res.data
						this.succTittle = res.data.result
						wx.showToast({
							title: this.succTittle,
							icon: 'none',
							duration: 2000
						});
					},
					fail: function(e) {
						wx.showToast({
							title: "服务器异常了",
							icon: 'none',
							duration: 2000
						});
					}
				});

				this.$refs.popup.close()
				uni.setStorageSync('plotNum', this.plotNum);

			},

			// 选择房屋
			chooseHouse() {
				uni.navigateTo({
					url: '/pages/selectBindHouse/selectBindHouse'
				});
			},

			// 查询已绑定的房屋
			chooseCar() {
				let commonUserNum = uni.getStorageSync("commonUser");
				this.phone = commonUserNum.phone; //小区id
				uni.request({
					url: constant.url.choiceHasHouse,
					header: context.getHeaders(),
					method: "GET",
					data: {
						phone: this.phone,
					},
					success: (res) => {
						this.houseCarTypes = res.data.result
					},
					fail: function(e) {
						wx.showToast({
							title: "服务器异常了",
							icon: 'none',
							duration: 2000
						});
					}
				});
			},

			// 选择房屋
			// chooseHouseTypes: function(e) {
			// 	console.log("e",e)
			// 	this.houseTypeIndex = e.target.value //取其下标
			// 	this.houseId = this.houseCarTypes[this.houseTypeIndex].id //获取选中的数组
			// },
			loadOwenrInfo: function() {
				let _that = this;

				context.getOwner(function(_ownerInfo) {
					console.log(_ownerInfo);

					if (_ownerInfo) {
						_that.ownerFlag = true;
						_that.ownerInfo = _ownerInfo;
					} else {
						_that.ownerFlag = false;
					}
				});
			},
			loadXqInfo() {
				let _that = this;
				uni.request({
					url: constant.url.queryCarDetails,
					header: context.getHeaders(),
					POST: "GET",
					data: {
						communityId: _that.plotCommunityId,
						examineObjectId: _that.examineObjectId //车位ID
					},
					//动态数据
					success: function(res) {
						_that.carDetails = res.data.data
						_that.psId = _that.carDetails.psId
						// }
					},
					fail: function(e) {
						wx.showToast({
							title: "服务器异常了",
							icon: 'none',
							duration: 2000
						});
					}
				});
			},
			// 解除车位绑定
			houseUnbundling: function(item) {
				this.delOwnerMemberFlag = true;
				this.curOwnerMember = item;
			},
			_cancleDeleteOwnerMember: function(item) {
				this.delOwnerMemberFlag = false;
			},
			_doDeleteOwnerMember: function() {
				let that = this;

				let commonUserId = uni.getStorageSync("commonUser");

				that.userId = commonUserId.id;
				uni.request({
					url: constant.url.deleteOwnerCar,
					header: context.getHeaders(),
					method: "POST",
					data: {
						proprietorId: that.userId,
						psId: that.psId,
						id: that.listId,
					},
					success: function(res) {
						console.log("res车位", res)
						let _json = res.data;
						if (_json.code == 0 || _json.code == 200) {
							wx.showToast({
								title: "解绑请求已成功",
								icon: 'none',
								duration: 2000
							});
							uni.navigateBack({
								url: '../parkingInfo/myParking',
							})
							that.loadXqInfo();
						} else {
							wx.showToast({
								title: "未知异常，请联系管理员",
								icon: 'none',
								duration: 2000
							});
						}
						that.delOwnerMemberFlag = false;

					},
					fail: function(e) {
						wx.showToast({
							title: "服务器异常了",
							icon: 'none',
							duration: 2000
						});
					}
				})
			}
		}
	};
</script>
<style scoped lang="scss">
	@import "@/pagesB/my/myHouseDetail.css";

	text {
		text-align: center;
	}

	.block__title {
		margin: 0;
		font-weight: 400;
		font-size: 14px;
		color: rgba(69, 90, 100, .6);
		padding: 40rpx 30rpx 20rpx;
	}

	.change_content {
		text-align: right;
		float: right;
	}

	.cu-form-group input {
		padding-right: 0rpx;
	}

	.bottomRegion {
		width: 100%;
		height: 100rpx;
		position: fixed;
		bottom: 20rpx;
		display: flex;
		justify-content: center;
		align-items: center;

		.vacantHouse {
			margin: 20rpx;
			width: 100%;
			text-align: center;
			height: 60rpx;
			display: flex;
			justify-content: space-around;
			font-size: 26rpx;
			line-height: 60rpx;

			button {
				float: left;
				width: 300rpx;
				font-size: 26rpx;
				height: 70rpx;
				margin-top: 15rpx;
				line-height: 70rpx;
				border-radius: 40rpx 40rpx;
			}
		}

	}
</style>
